package demo.servlet;

import servlet.HttpProtocolUtil;
import servlet.HttpServlet;
import servlet.Request;
import servlet.Response;

import java.io.IOException;

/**
 * Created by louisyuu on 2020/4/2 上午9:48
 */
public class DemoServlet extends HttpServlet {


    @Override
    protected void doGet(Request request, Response response) throws Exception {
        doPost(request, response);


    }

    @Override
    protected void doPost(Request request, Response response) throws Exception {


        System.out.println("Request to demo servlet");
        System.out.println("Request method type " + request.getMethod());
        System.out.println("Request url " + request.getUrl());


        String content = "<h1>DemoServlet post from web-demo-two</h1>";
        try {
            response.output((HttpProtocolUtil.getHttpHeader200(content.getBytes().length) + content));
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
